<?php
/**
 * Created by PhpStorm.
 * User: W
 * Date: 2018/12/24
 * Time: 16:18
 */

namespace app\sports_admin\service;
use think\db;
use think\Request;
use app\sports_admin\model\DataCategory;

class BookTypes
{
    //添加
    public static function addType()
    {
        $data  = Request::instance()->only("catname,pid");
        //根据pid查询出level
        $level = DataCategory::where('id',$data['pid'])->field("id,level")->find();
        $level = $level['level']+1;
        return DataCategory::insert(["pid"=>$data['pid'],"catname"=>$data['catname'],"level"=>$level]);
    }
    //某个类型  父级信息
    public static function update()
    {
        $data = Request::instance()->only("id,pid,catname");
        $level = DataCategory::where('id',$data['pid'])->field("id,level")->find();
        $level = $level['level']+1;
        return DataCategory::where("id",$data['id'])->update(["pid"=>$data['pid'],"catname"=>$data['catname'],"level"=>$level]);
    }
    //

}